package com.hualan.servlet;

import com.alibaba.fastjson.JSON;
import com.hualan.dao.CommunityListDao;
import com.hualan.dao.impl.CommunityListDaoImpl;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/communityList/delete")
public class CommunityListDeleteServlet extends HttpServlet {

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       doPost(req, resp);

    }

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //通过id删除
        int id = Integer.parseInt(req.getParameter("communityId"));
        CommunityListDao communityListDao = new CommunityListDaoImpl();
        int row = communityListDao.deleteCommunityById(id);
        Map<String, Object> map = new HashMap<>();
        if(row > 0){
            map.put("code", 200);
        }else{
            map.put("code", 300);
        }
        resp.getWriter().write(JSON.toJSONString(map));

    }

}
